// exports.PlatformCommon = void 0;
// (function (e) {
//     function t(e, t) {
//         var n = cc.view.getFrameSize();
//         var o = cc.misc.clamp01(e / cc.winSize.width);
//         var i = cc.misc.clamp01(1 - t / cc.winSize.height);
//         return {
//             left: n.width * o,
//             top: n.height * i
//         };
//     }

//     function n(e, t) {
//         var n = cc.view.getFrameSize();
//         var o = n.width / cc.winSize.width;
//         var i = n.height / cc.winSize.height;
//         return cc.size(e * o, t * i);
//     }
//     e.huoqu_shijie_zuobiao_zhuanhuan_dao_zhen_zuobiao_weizhi = function (e, t) {
//         var n = cc.view.getFrameSize();
//         var o = e / n.width;
//         var i = t / n.height;
//         var r = o * cc.winSize.width;
//         var a = i * cc.winSize.height;
//         return cc.v2(r, a);
//     };
//     e.huoqu_zhen_chicun_dao_shijie_chicun_daxiao = function (e, t) {
//         var n = cc.view.getFrameSize();
//         var o = cc.winSize.width / n.width;
//         var i = cc.winSize.height / n.height;
//         return cc.size(e * o, t * i);
//     };
//     e.huoqu_jiedian_weizhi_zhuandao_zhen_weizhi_zuobiao = function (e) {
//         var n = cc.mat4();
//         e.getWorldMatrix(n);
//         var o = cc.v3();
//         var i = cc.v3();
//         var r = e.width;
//         var a = e.height;
//         n.getTranslation(o);
//         n.getScale(i);
//         var s = i.x;
//         var c = cc.v2(o).add(cc.v2((0 - e.anchorX) * r * s, (1 - e.anchorY) * a * s));
//         return t(c.x, c.y);
//     };
//     e.huoqu_shijiezuobiao_dao_zhen_zuobiao = t;
//     e.huoqu_shijiechicun_dao_zhen_chicun = n;
//     e.huoqu_jiedian_dao_zhen_de_juxing = function (e) {
//         var i = cc.mat4();
//         e.getWorldMatrix(i);
//         var r = cc.v3();
//         var a = cc.v3();
//         var s = e.width;
//         var c = e.height;
//         i.getTranslation(r);
//         i.getScale(a);
//         var l = a.x;
//         var u = cc.v2(r).add(cc.v2((0 - e.anchorX) * s * l, (1 - e.anchorY) * c * l));
//         var p = t(u.x, u.y);
//         var f = n(s * l, c * l);
//         return __assign(__assign({}, p), {
//             width: f.width,
//             height: f.height
//         });
//     };
// })(exports.PlatformCommon || (exports.PlatformCommon = {}));


exports.PlatformCommon = void 0;

/** 平台通用功能模块*/
(function (Namespace) {

    /**
     * 将世界坐标转换为帧坐标
     * @param {number} worldX 世界坐标的x
     * @param {number} worldY 世界坐标的y
     * @returns {{left: number, top: number}} 帧坐标中的left和top
     */
    function world_To_Frame_Position(worldX, worldY) {
        const frameSize = cc.view.getFrameSize();
        const clampX = cc.misc.clamp01(worldX / cc.winSize.width);
        const clampY = cc.misc.clamp01(1 - worldY / cc.winSize.height);
        return {
            left: frameSize.width * clampX,
            top: frameSize.height * clampY
        };
    }

    /**
     * 将世界尺寸转换为帧尺寸
     * @param {number} worldWidth 世界尺寸的宽度
     * @param {number} worldHeight 世界尺寸的高度
     * @returns {Size} 转换后的帧尺寸
     */
    function world_To_Frame_Size(worldWidth, worldHeight) {
        const frameSize = cc.view.getFrameSize();
        const widthRatio = frameSize.width / cc.winSize.width;
        const heightRatio = frameSize.height / cc.winSize.height;
        return cc.size(worldWidth * widthRatio, worldHeight * heightRatio);
    }

    /**
     * 获取世界坐标转换到帧坐标的位置
     * @param {number} frameX 帧坐标的x
     * @param {number} frameY 帧坐标的y
     * @returns {Vec2} 世界坐标中的位置
     */
    Namespace.huoqu_shijie_zuobiao_zhuanhuan_dao_zhen_zuobiao_weizhi = function (frameX, frameY) {
        const frameSize = cc.view.getFrameSize();
        const xRatio = frameX / frameSize.width;
        const yRatio = frameY / frameSize.height;
        const worldX = xRatio * cc.winSize.width;
        const worldY = yRatio * cc.winSize.height;
        return cc.v2(worldX, worldY);
    };

    /**
     * 获取帧尺寸转换到世界尺寸的大小
     * @param {number} frameWidth 帧尺寸的宽度
     * @param {number} frameHeight 帧尺寸的高度
     * @returns {Size} 世界尺寸大小
     */
    Namespace.huoqu_zhen_chicun_dao_shijie_chicun_daxiao = function (frameWidth, frameHeight) {
        const frameSize = cc.view.getFrameSize();
        const widthRatio = cc.winSize.width / frameSize.width;
        const heightRatio = cc.winSize.height / frameSize.height;
        return cc.size(frameWidth * widthRatio, frameHeight * heightRatio);
    };

    /**
     * 获取节点位置转换到帧位置的坐标
     * @param {Node} node 要转换的节点
     * @returns {{left: number, top: number}} 帧坐标中的left和top
     */
    Namespace.huoqu_jiedian_weizhi_zhuandao_zhen_weizhi_zuobiao = function (node) {
        const worldMatrix = cc.mat4();
        node.getWorldMatrix(worldMatrix);
        const translation = cc.v3();
        const scale = cc.v3();
        const width = node.width;
        const height = node.height;
        worldMatrix.getTranslation(translation);
        worldMatrix.getScale(scale);
        const scaleX = scale.x;
        const transformation = cc.v2(translation).add(cc.v2((0 - node.anchorX) * width * scaleX, (1 - node.anchorY) * height * scaleX));
        return world_To_Frame_Position(transformation.x, transformation.y);
    };

    // 将世界坐标转换为帧坐标
    Namespace.huoqu_shijiezuobiao_dao_zhen_zuobiao = world_To_Frame_Position;
    // 将世界尺寸转换为帧尺寸
    Namespace.huoqu_shijiechicun_dao_zhen_chicun = world_To_Frame_Size;

    /**
     * 获取节点到帧的矩形
     * @param {Node} node 要转换的节点
     * @returns {object} 矩形中的位置和大小
     */
    Namespace.huoqu_jiedian_dao_zhen_de_juxing = function (node) {
        const worldMatrix = cc.mat4();
        node.getWorldMatrix(worldMatrix);
        const translation = cc.v3();
        const scale = cc.v3();
        const width = node.width;
        const height = node.height;
        worldMatrix.getTranslation(translation);
        worldMatrix.getScale(scale);
        const scaleX = scale.x;
        const transformation = cc.v2(translation).add(cc.v2((0 - node.anchorX) * width * scaleX, (1 - node.anchorY) * height * scaleX));
        const position = world_To_Frame_Position(transformation.x, transformation.y);
        const size = world_To_Frame_Size(width * scaleX, height * scaleX);
        return { ...position, width: size.width, height: size.height };
    };
    
})(exports.PlatformCommon || (exports.PlatformCommon = {}));